#include "HufArc.h"

unsigned char * makeTables (unsigned char alpha,int flag,__HufTree * head,unsigned char * i)
{
	char ed[] = "1";
	char nu[] = "0";
	unsigned char * code = NULL;
	unsigned char * m;
	if (i)
	{
		m = (unsigned char *) calloc (strlen((char*)i)+2,sizeof(char));
		strcat ((char*)m,(char*)i);
	} else
		m = (unsigned char *) calloc (2,sizeof(char));

	if (flag == -1)
		strcat ((char*)m,nu);
	if (flag == 1)
		strcat ((char*)m,ed);
	if (head->left)
		code = makeTables (alpha,-1,head->left,m);
	if (code)
		return code;
	if (!head->flag)
	{
		if (alpha == head->alpha)
			code = m;
		return code;
		//system ("pause");
	}
	if (head->right)
		code = makeTables (alpha,1,head->right,m);
	if (code)
		return code;
	return NULL;
}
